<?php
	class LoginControl extends Control{
	function __auto(){
		if(isset($_SESSION['uid'])){
			go("index/index");
		}
	}
	//登录入口
    function login(){
    	$this->display();
    }
    //登录
    function userLogin(){

        if(strtoupper($_POST['code']) !=strtoupper($_SESSION['code'])){
            $this->error('验证码错误','login');
        die();
        }
    	$db = M("user");
    	$username = $this->_POST("username");
    	if($username){
    		if($user = $db->find("username='$username'")){
    			if($user['password'] ==md5($_POST['password'])){
    				$_SESSION['uid']=$user['userid'];
    				$_SESSION['username']=$user['username'];
    				go("index/index");
    			}else{
    				$this->error("密码错误","login");
    			}
    		}else{
    			$this->error("用户不存在");
    		}
    	}
    }
    //获取验证码
    function getcode(){
        $code=new code();
        $code->show();
        }
	}
?>